package com.learn.rocketmq.simple;

import org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyContext;
import org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyStatus;
import org.apache.rocketmq.client.consumer.listener.MessageListenerConcurrently;
import org.apache.rocketmq.common.message.MessageExt;

import java.nio.charset.StandardCharsets;
import java.util.List;

/**
 * 消息侦听器
 *
 * @date 2021/08/16
 */
public class MessageListener implements MessageListenerConcurrently {

    @Override
    public ConsumeConcurrentlyStatus consumeMessage(List<MessageExt> list, ConsumeConcurrentlyContext consumeConcurrentlyContext) {
        if (list != null && list.size() > 0) {
            for (MessageExt msg : list) {
                System.out.println("监听到消息 : " + new String(msg.getBody(), StandardCharsets.UTF_8));
            }
        }
        return ConsumeConcurrentlyStatus.CONSUME_SUCCESS;
    }

}
